package cn.huobi.controller;

import cn.huobi.block.GetUserByIdBlockHandler;
import cn.huobi.fallback.GetUserByIdFallback;
import cn.huobi.feign.UserService;
import cn.huobi.user.domain.User;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private UserService userService;

    @GetMapping("/{id}")
    @SentinelResource(value = "getUserById",blockHandler = "getUserByIdFallback",blockHandlerClass = GetUserByIdBlockHandler.class)
   // @SentinelResource(value = "getUserById",fallback = "getUserByIdFallback",fallbackClass = GetUserByIdFallback.class)
    public User getUserById(@PathVariable("id") Long id){
        User user = userService.getUserById(id);
        //int i = 1/0;
        return user;
    }

//    public User getUserByIdFallback(@PathVariable("id") Long id, BlockException blockException){
//        return new User(-1L, "限流", "装不下了，快出去！！！");
//    }

//    public User getUserByIdFallback(@PathVariable("id") Long id,Throwable throwable){
//        return new User(-1L, "熔断", "已经断了，不来了！！！");
//    }
}
